#include <iostream>
#include <cstdio>
#include <cerrno>
#include <cstring>
#include <cassert>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include "comm.hpp"

int main()
{
    //以写方式打开管道
    int w_fd = open(fifoname.c_str(),O_WRONLY);
    if(w_fd < 0)
    {
        std::cout << errno << ":" << strerror(errno) << std::endl;
    }

    //进行通信
    char buffer[NUM];
    while(true)
    {
        std::cout << "请输入消息#";
        
        char* msg = fgets(buffer,sizeof(buffer),stdin);
        assert(msg);(void)msg;
        
        //1 2 3 4 5 /n/0
        //0 1 2 3 4 5 /0
        buffer[strlen(buffer)-1] = 0;
        if(strcasecmp(buffer,"quit") == 0) break;
        ssize_t n = write(w_fd,buffer,sizeof(buffer)-1);
    }
    return 0;
}